{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Copyright (C) 2016 - 2019 Pinard Liu(liujianping-ok@163.com)\n",
    "\n",
    "https://www.cnblogs.com/pinard\n",
    "\n",
    "Permission given to modify the code as long as you keep this declaration at the top\n",
    "\n",
    "文本主题模型之非负矩阵分解(NMF) https://www.cnblogs.com/pinard/p/6812011.html"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "X = np.array([[1,1,5,2,3], [0,6,2,1,1], [3, 4,0,3,1], [4, 1,5,6,3]])\n",
    "from sklearn.decomposition import NMF\n",
    "model = NMF(n_components=2, alpha=0.01)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1.67371185  0.02013017]\n",
      " [ 0.40564826  2.17004352]\n",
      " [ 0.77627836  1.5179425 ]\n",
      " [ 2.66991709  0.00940262]]\n",
      "[[ 1.32014421  0.40901559  2.10322743  1.99087019  1.29852389]\n",
      " [ 0.25859086  2.59911791  0.00488947  0.37089193  0.14622829]]\n"
     ]
    }
   ],
   "source": [
    "W = model.fit_transform(X)\n",
    "H = model.components_\n",
    "print W\n",
    "print H"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
